<template>
  <van-list
    v-model:loading="listLoading"
    v-model:error="listError"
    :finished="props.finished"
    :finished-text="finishedText"
    :error-text="errorText"
    :immediate-check="immediateCheck"
    @load="load"
    @touchmove.stop
  >
    <slot></slot>
  </van-list>
</template>

<script lang="ts">
export default {
  name: 'BaseList'
}
</script>

<script setup lang="ts">
import { computed } from 'vue'

const emit = defineEmits(['load', 'update:loading', 'update:error'])

const props = defineProps({
  loading: {
    type: Boolean,
    required: true
  },
  error: {
    type: Boolean,
    required: true
  },
  finished: {
    type: Boolean,
    required: true
  },
  finishedText: {
    type: String,
    default: '没有更多了'
  },
  errorText: {
    type: String,
    default: '请求失败，点击重新加载'
  },
  immediateCheck: {
    type: Boolean,
    default: false
  }
})

const listLoading = computed({
  get() {
    return props.loading
  },
  set(val: boolean) {
    emit('update:loading', val)
  }
})

const listError = computed({
  get() {
    return props.error
  },
  set(val: boolean) {
    emit('update:error', val)
  }
})

const load = () => {
  emit('load')
}
</script>
<style lang="scss" scoped></style>
